//
//  BookCityChildViewController.m
//  WNZSSQ
//
//  Created by JDKJ on 2018/12/6.
//  Copyright © 2018年 JDKJ. All rights reserved.
//

#import "BookCityChildViewController.h"
#import "FSPageContentView.h"
#import "FSSegmentTitleView.h"
#import "BookCityView.h"
#import "BookCitySearchViewController.h"
#import "UserNavigationController.h"
#import "BookDetalViewController.h"

@interface BookCityChildViewController ()<FSPageContentViewDelegate,FSSegmentTitleViewDelegate,UICollectionViewDataSource,UICollectionViewDelegate>

//选择1
@property(nonatomic,weak)FSSegmentTitleView *seletTitleView1;

//选择2
@property(nonatomic,weak)FSSegmentTitleView *seletTitleView2;

//选择3
@property(nonatomic,weak)FSSegmentTitleView *seletTitleView3;

//选择4
@property(nonatomic,weak)FSSegmentTitleView *seletTitleView4;

@property(nonatomic,weak)FSPageContentView *pageContentView;

@property(nonatomic,weak)UICollectionView *collectionView;

@property(nonatomic,weak)UICollectionViewFlowLayout *collectViewFlowLayout;

@property(nonatomic,weak)BookCityView *headView;

@end

@implementation BookCityChildViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self creatUI];
    
}

-(void)creatUI
{
    
    
    
    
    //
    UICollectionViewFlowLayout *collectViewFlowLayout = [[UICollectionViewFlowLayout alloc] init];
    self.collectViewFlowLayout = collectViewFlowLayout;
    //设置cell之间间距
    collectViewFlowLayout.minimumInteritemSpacing = 30;
    //设置行距
    collectViewFlowLayout.minimumLineSpacing = 12;
    collectViewFlowLayout.sectionInset = UIEdgeInsetsMake(15, 15, 15, 15);
    CGFloat itemWith = (SCREEN_WIDTH - 90) / 3;
    
    collectViewFlowLayout.headerReferenceSize = CGSizeMake(SCREEN_WIDTH, 170);
    
    //设置Item大小
    collectViewFlowLayout.estimatedItemSize = CGSizeMake(itemWith, itemWith + 60);
    //    collectViewFlowLayout.itemSize = CGSizeMake(itemWith, itemWith + 60);
    UICollectionView *collectionView = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:collectViewFlowLayout];
    collectionView.showsHorizontalScrollIndicator = NO;
    collectionView.showsVerticalScrollIndicator = NO;
    collectionView.backgroundColor = CSClearColor;
    collectionView.delegate = self;
    collectionView.dataSource = self;
    [collectionView registerClass:[BookCityViewCell class] forCellWithReuseIdentifier:@"BookCityViewCell"];
    [collectionView registerClass:[BookCityView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader  withReuseIdentifier:@"head"];
    
    [self.view addSubview:collectionView];
    self.collectionView = collectionView;
    
    MJRefreshAutoNormalFooter *footer = [MJRefreshAutoNormalFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
    footer.automaticallyHidden = YES;
    
    collectionView.mj_footer = footer;
    //    [self.collectionView.mj_footer endRefreshingWithNoMoreData];
    //    MJRefreshHeader *head = [MJRefreshHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadStartData)];
    //    collectionView.mj_header = head;
    [collectionView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.bottom.left.width.mas_equalTo(self.view);
        
    }];
    
}

#pragma mark UICollectionViewDataSource
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    return 4;
    
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    
    BookCityViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"BookCityViewCell" forIndexPath:indexPath];
    
    
    
    return cell;
    
    
}

//设置cell的大小


- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
    
    UICollectionReusableView *reusableview = nil;
    
    if (kind == UICollectionElementKindSectionHeader){
        
        
        BookCityView *headView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"head" forIndexPath:indexPath];
        
        
        return headView;
        
        
        
    }
    return reusableview;
    
}



-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
    
    BookDetalViewController *detailVC = [[BookDetalViewController alloc]init];
    
    [self.navigationController pushViewController:detailVC animated:YES];
    
    
}

#pragma mark UIScrollViewDelegate
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
    
    
    
    
    
}



#pragma mark FSSegmentTitleViewDelegate

- (void)FSSegmentTitleView:(FSSegmentTitleView *)titleView startIndex:(NSInteger)startIndex endIndex:(NSInteger)endIndex
{
    
    //改变底部指示位置
    UIButton *btn4 = (UIButton *)[titleView viewWithTag:666 +endIndex];
    
    [titleView.indicatorView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.edges.mas_equalTo(btn4);
        
        
        
    }];
    
}



@end
